import "../static/libs/flexible"
import "../scss/common.scss"
import "../scss/startTest.scss"
import http from "../utils/http"

//类型id
const typeId = location.search.substr(1).split("-")[0]

//试卷id
const testId = location.search.substr(1).split("-")[1]

async function main() {
    //根据类型id获取数据
    const { data } = await http({ url: "/types/findById?id=" + typeId })
    //根据试卷id获取数据
    const test = await http({ url: "/tests/findById?id=" + testId })
    //渲染考试信息
    renderTestInfo(data.type, test.data)

    //渲染考生信息
    renderStuInfo()

    toExercises()//点击跳转到答题页面

    back()//返回上一页
}
main()

//渲染考试信息
function renderTestInfo(type, test) {
    //渲染标题
    $(".container .text").text(test.title)
    //渲染考试信息
    $(".container .testInfo").html(`
    <p>考试类型:&nbsp;<span> ${type}</span></p>
    <p>考试时间:&nbsp;<span> ${test.starttime}~${test.endtime}</span></p>
    <p>答卷时间:&nbsp;<span> ${test.durations}分钟</span></p>
    <p>考试方式:&nbsp;<span> 线上</span></p>
    `)
}

//渲染考生信息
function renderStuInfo() {
    const userInfo = JSON.parse(localStorage.getItem("userInfo") || "{}")
    $(".container .stuInfo").html(`
    <p>姓名:&nbsp;<span> ${userInfo.name}</span></p>
    <p>证件号码:&nbsp;<span> 3423445234634451231</span></p>
    <p>部门:&nbsp;<span> 信息中心</span></p>
    `)
}

//点击跳转到答题页面
function toExercises() {
    $(".content #check").on("click", function () {
        window.location.assign("exercises.html?" + typeId + "-" + testId)
    })
}

//点击返回
function back() {
    $("#back").on("click", function () {
        window.history.back()
    })
}
